<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <!-- 树形菜单选择 -->
    <link rel="stylesheet" type="text/css" href="/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="/easyui/themes/icon.css">
    <link rel="stylesheet" href="/cn/css/element.css">
    <link rel="stylesheet" href="/cn/css/index.css?v=1.1">
    <script type="text/javascript" src="https://file.viplgw.cn/ui/public/js/jquery-1.9.1.min.js?v=1.1.1"></script>
    <script type="text/javascript" src="https://file.viplgw.cn/ui/public/lib/vue/vue.js?v=1.1.1"></script>
    <script type="text/javascript" src="https://file.viplgw.cn/ui/public/lib/element-ui/index.js?v=1.1.3"></script>
    <script type="text/javascript" src="/easyui/jquery.easyui.min.js"></script>
</head>
<style type="text/css">
table.gridtable {    font-family: verdana,arial,sans-serif;    font-size:11px;    color:#333333;    border-width: 1px;    border-color: #666666;    border-collapse: collapse;}
table.gridtable th {    border-width: 1px;    padding: 8px;    border-style: solid;    border-color: #666666;    background-color: #dedede;}
table.gridtable td {    border-width: 1px;    padding: 8px;      border-color: #666666;    background-color: #ffffff;
}
</style>

<body>


    <table class="gridtable">
   
    <tr id="tbody">    
            <th>
                id
                <td>
                name
                </td>
                <td>
                url
                </td>
                <td>
                排序
                </td>
                <td>
                类型 (1雅思培训 2英语培训 3友情链接 4wap底部快速入口)
                </td>
                <td>
                操作        <input type="button" value="新增"  onclick="add( )">
                </td>
            </th>
  
    </tr>


    <?php  foreach($block as $v ){?>
        <tr id="tr<?php echo $v['id'] ?>">     
            <th >
            <?php echo $v['id'] ?>
            <td>
                    <input type="text" value="<?php echo $v['name']?>"  id="name<?php echo $v['id'] ?>">
            </td>
            <td>
                    <input type="text" value="<?php echo $v['url']?>"   id="url<?php echo $v['id'] ?>">
            </td>
            <td>
                    <input type="text" value="<?php echo $v['sort']?>"   id="sort<?php echo $v['id'] ?>">
            </td>
            <td>
                    <input type="text" value="<?php echo $v['type']?>"   id="type<?php echo $v['id'] ?>">
            </td>
 
            <td>
                <input type="button" value="提交" onclick="update(<?php echo $v['id']?>)" >

                <input type="button" value="x" onclick="delSc(<?php echo $v['id']?>)" >
                 <!-- <a href="javascript:" onclick="delSc(<?php echo $v['id']?>)"> &nbsp; &nbsp; &nbsp;x</a></span></a>  -->
            </td>
            </th>
  
        </tr>
        <?php  }?>
    </table>
</body>

<script type="text/javascript" >
    // 添加 sjeam
    function add( ) {
        $.ajax({
            url: "/content/block/add",
            dataType: "json",
            data: {
            },
            type: "POST",
            success: function (data) {
                if(data.code==1){
                    var data =data.data;
                    var str ='<tr id="tr'+data.id+'">  <th >'+data.id+'<td> <input type="text" value="'+data.name+'"  id="name'+data.id+'"> </td> <td> <input type="text" value="'+data.url+'"  id="url'+data.id+'"> </td> <td> <input type="text" value="'+data.sort+'"  id="sort'+data.id+'"> </td>  <td><input type="text" value="'+data.type+'"  id="type'+data.id+'"> </td> <td><input type="button" value="提交" onclick="update('+data.id+')" > <input type="button" value="x" onclick="delSc('+data.id+')" >  </td>  </th ></tr>';
                    $("#tbody").after(str);
                }else{
                    location.reload();
                }
            }
        })
        
   

    }
    // 删除 sjeam
    function delSc(id) {
        var r = confirm("是否删除当前岗位！！！");
        if (r == true) {  
            $.ajax({
                url: "/content/block/delete",
                dataType: "json",
                data: {
                    id: id
                },
                type: "POST",
                success: function (res) {
                    if(res.code==1){
                        $('#tr'+id).remove();
                    }else{
                        location.reload();
                    }
                }
            })
        }
        else {
            return false;
        }

    }


        // 提交 sjeam
        function update(id) {
        var r = confirm("是否提交当前链接！！！");
        if (r == true) {  
            var name =$("#name"+id).val();
            var url =$("#url"+id).val();
            var sort =$("#sort"+id).val();
            var type =$("#type"+id).val();

            
            // console.log(sort )
            $.ajax({
                url: "/content/block/update",
                dataType: "json",
                data: {
                    id: id,
                    name: name,
                    url: url,
                    sort: sort,
                    type: type,
                },
                type: "POST",
                success: function (res) {
                    if(res.code==1){
                        // $('#td'+id).remove();
                        name =$("#name"+id).val(name);
                        url =$("#url"+id).val(url );
                        sort =$("#sort"+id).val(sort);
                        type =$("#type"+id).val(type);
                    }else{
                        location.reload();
                    }
                }
            })
        }
        else {
            return false;
        }

    }
        

</script>

</html>